package CaraOCruz;

import javax.swing.JOptionPane;

public class CaraCruz {

	public static void main(String[] args) {
		int Njuegos = 0, JoWon = 0, MaWon = 0;
		String Ri = null;
		boolean error = false;
		do {
			error = true;
			while (error == true) {
				try {
					Njuegos = Integer.parseInt(JOptionPane.showInputDialog(
							null, "Ingrese numero de juegos jugados"));
					error = false;
				} catch (Exception e) {
					JOptionPane.showMessageDialog(null,
							"Solo se permiten numeros");
					error = true;
				}
			}
			if (Njuegos != 0) {
				try {
					Ri = JOptionPane.showInputDialog(null, "Lista resultados");
				} catch (Exception e) {
					JOptionPane.showMessageDialog(null,
							"Solo se permiten numeros");
				}
				String[] Resultados = Ri.split(" ");
				for (int i = 0; Njuegos > i; i++) {
					if (Resultados[i].equals("0")) {
						MaWon = MaWon + 1;
					} else {
						if (Resultados[i].equals("1")) {
							JoWon = JoWon + 1;
						}
					}
				}

			}

		} while (Njuegos != 0);
		if ((MaWon != 0) || (JoWon != 0)) {
			JOptionPane.showMessageDialog(null, "Mary won " + MaWon
					+ " times and Jhon won " + JoWon + " times");
		}
	}
}